#!/usr/bin/env python
# -*- encoding: utf-8 -*-
# Project: spd-sxmcc
"""
@file: gk1.py
@author: lyndon
@time: Created on 2022-02-17 19:36
@env: Python
@desc:
@ref:
@blog:
"""

from time import sleep
from selenium import webdriver
from selenium.common.exceptions import NoSuchElementException
from selenium.webdriver.common.by import By

browser = webdriver.Chrome("D:\iSoft\chromedriver_win32\chromedriver.exe")
sleep(0.5)
browser.get("https://wxtime.geekbang.org/course/intro/100060601?tab=catalog")
sleep(28)  # 等待页面加载, 扫码登录，手动点击到课程页
browser.find_element(By.CLASS_NAME, 'GkPlayer_fullscreenOffBtn_3ZIlN').click()  # 全屏
sleep(2)
w = browser.find_element(By.CLASS_NAME, "GkPlayer_bigPlayIcon_1uopO")
w.click()  # 播放

sleep(2)
while True:
    print('listening...')
    try:
        sleep(2)
        w = browser.find_element(By.CLASS_NAME, "GkPlayer_bigPlayIcon_1uopO")
        # TODO 不断

    except Exception as e:
        continue
    if w.is_enabled():
        print('stop')
        break

sleep(30)
# 退出
browser.close()
browser.quit()
